﻿using Newtonsoft.Json;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using XW.Core;

namespace XW.Data;

/// <summary>
/// 用户实体
/// </summary>
[SugarTable(null, TableDescription = "用户表")] 
public class SysUser: EntityBase
{
    /// <summary>
    /// 账号
    /// </summary>
    [SugarColumn(ColumnDescription = "账号", Length = 32)]
    [Required, MaxLength(32)]
    public virtual string Account { get; set; }

    /// <summary>
    /// 盐
    /// </summary>
    [SugarColumn(ColumnDescription = "盐", Length = 10)] 
    public string Salt { get; set; }
    /// <summary>
    /// 密码
    /// </summary>
    [SugarColumn(ColumnDescription = "密码", Length = 512)]
    [MaxLength(512)]
    [System.Text.Json.Serialization.JsonIgnore]
    [JsonIgnore]
    public virtual string Password { get; set; }

    /// <summary>
    /// 真实姓名
    /// </summary>
    [SugarColumn(ColumnDescription = "真实姓名", Length = 32)]
    [MaxLength(32)]
    public virtual string RealName { get; set; }

    /// <summary>
    /// 昵称
    /// </summary>
    [SugarColumn(ColumnDescription = "昵称", Length = 32)]
    [MaxLength(32)]
    public string? NickName { get; set; }

    /// <summary>
    /// 头像
    /// </summary>
    [SugarColumn(ColumnDescription = "头像", Length = 512)]
    [MaxLength(512)]
    public string? Avatar { get; set; }


    /// <summary>
    /// 手机号码
    /// </summary>
    [SugarColumn(ColumnDescription = "手机号码", Length = 16)]
    [MaxLength(16)]
    public string? Phone { get; set; }


    /// <summary>
    /// 电话号码
    /// </summary>
    [SugarColumn(ColumnDescription = "电话号码", Length = 200)]
    [MaxLength(200)]
    public string? Email { get; set; }

    /// <summary>
    /// 排序
    /// </summary>
    [SugarColumn(ColumnDescription = "排序")]
    public int OrderNo { get; set; } = 100;

    /// <summary>
    /// 状态 0  停用  1 启用
    /// </summary>
    [SugarColumn(ColumnDescription = "状态")]
    public int Status { get; set; } = 1;

    /// <summary>
    /// 自我介绍
    /// </summary>
    [SugarColumn(ColumnDescription = "自我介绍", Length = 256)]
    [MaxLength(256)]
    public string? Introduc { get; set; }
    /// <summary>
    /// 备注
    /// </summary>
    [SugarColumn(ColumnDescription = "备注", Length = 256)]
    [MaxLength(256)]
    public string? Remark { get; set; }

    /// <summary>
    /// 账号类型
    /// 999 管理员
    /// </summary>
    [SugarColumn(ColumnDescription = "账号类型")]
    public int AccountType { get; set; } = 0;
     
    /// <summary>
    /// 最新登录Ip
    /// </summary>
    [SugarColumn(ColumnDescription = "最新登录Ip", Length = 256)]
    [MaxLength(256)]
    public string? LastLoginIp { get; set; }

    /// <summary>
    /// 最新登录地点
    /// </summary>
    [SugarColumn(ColumnDescription = "最新登录地点", Length = 128)]
    [MaxLength(128)]
    public string? LastLoginAddress { get; set; }

    /// <summary>
    /// 最新登录时间
    /// </summary>
    [SugarColumn(ColumnDescription = "最新登录时间")]
    public DateTime? LastLoginTime { get; set; }


    /// <summary>
    /// 组织Id
    /// </summary>
    [SugarColumn(ColumnDescription = "组织Id")]
    public long OrgId { get; set; }


    /// <summary>
    /// 菜单类型 0 普通菜单 1 按钮
    /// </summary>
    [SugarColumn(IsIgnore = true)]
    public virtual List<long> Roles { get; set; }
}


/// <summary>
/// 用户实体
/// </summary>
[SugarTable(null, TableDescription = "用户角色表")]
public class SysUserRole : EntityBase {

    /// <summary>
    /// 用户Id
    /// </summary>
    [JsonConverter(typeof(LongJsonConverter))]
    [SugarColumn(ColumnDescription = "用户id")]
    public virtual long UserId { get; set; }

    /// <summary>
    /// 角色id
    /// </summary>
    [JsonConverter(typeof(LongJsonConverter))]
    [SugarColumn(ColumnDescription = "角色id")]
    public virtual long RoleId { get; set; }
}